#include <stdio.h>
#include <stdarg.h>

typedef char *sds;

struct sdshdr
{
    long len;
    long free;
    char buf[];
};

struct sdshdr sh = {6, 2, {'h', 'e', 'l', 'l', 'o', '\0'}};

int my_snprintf(char *s, int size, const char *fmt, ...)
{
    va_list ap;
    int n = 0;
    va_start(ap, fmt);
    n = vsnprintf(s, size, fmt, ap);
    va_end(ap);
    return n;
}

int main()
{
    /* code */
    struct sdshdr *s = &sh;

    printf("%d\n", sizeof(struct sdshdr));
    printf("%d\n", sizeof(long));
    printf("%d,%p\n", s->len, &(s->len));
    printf("%d,%p\n", s->free, &(s->free));
    printf("%s,%p\n", s->buf, &(s->buf));

    sds sd = s->buf;
    printf("%s\n", sd);

    // sdshdr开始指针
    struct sdshdr *new_sh = (void *)(sd - sizeof(struct sdshdr));
    printf("len:%d,\tfree:%d\n", new_sh->len, s->free);

    char str[1024];
    my_snprintf(str, sizeof(str), "%d,%s,%d,%d\n", 5, "nihao", 7, 8);
    printf("%s\n", str);
    return 0;
}
